import axios from './axios'
import type { AxiosRequestConfig } from 'axios'

// 定义返回数据的类型
export interface ResponseData<T = any> {
  code: number
  message: string
  data: T
}

// 封装get请求
export const get = <T = any>(
  url: string,
  params?: any,
  config?: AxiosRequestConfig,
): Promise<ResponseData<T>> => {
  return axios.get(url, { params, ...config })
}

// 封装post请求
export const post = <T = any>(
  url: string,
  data?: any,
  config?: AxiosRequestConfig,
): Promise<ResponseData<T>> => {
  return axios.post(url, data, config)
}

// 封装put请求
export const put = <T = any>(
  url: string,
  data?: any,
  config?: AxiosRequestConfig,
): Promise<ResponseData<T>> => {
  return axios.put(url, data, config)
}

// 封装delete请求
export const del = <T = any>(
  url: string,
  data?: any,
  config?: AxiosRequestConfig,
): Promise<ResponseData<T>> => {
  return axios.delete(url, { data, ...config })
}
